1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.SelectionModelIF;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.Bitset;
30 private import gtk.c.functions;
31 public  import gtk.c.types;
32 private import std.algorithm;
33 
34 
35 /**
36  * `GtkSelectionModel` is an interface that add support for selection to list models.
37  * 
38  * This support is then used by widgets using list models to add the ability
39  * to select and unselect various items.
40  * 
41  * GTK provides default implementations of the most common selection modes such
42  * as [class@Gtk.SingleSelection], so you will only need to implement this
43  * interface if you want detailed control about how selections should be handled.
44  * 
45  * A `GtkSelectionModel` supports a single boolean per item indicating if an item is
46  * selected or not. This can be queried via [method@Gtk.SelectionModel.is_selected].
47  * When the selected state of one or more items changes, the model will emit the
48  * [signal@Gtk.SelectionModel::selection-changed] signal by calling the
49  * [method@Gtk.SelectionModel.selection_changed] function. The positions given
50  * in that signal may have their selection state changed, though that is not a
51  * requirement. If new items added to the model via the
52  * [signal@Gio.ListModel::items-changed] signal are selected or not is up to the
53  * implementation.
54  * 
55  * Note that items added via [signal@Gio.ListModel::items-changed] may already
56  * be selected and no [signal@Gtk.SelectionModel::selection-changed] will be
57  * emitted for them. So to track which items are selected, it is necessary to
58  * listen to both signals.
59  * 
60  * Additionally, the interface can expose functionality to select and unselect
61  * items. If these functions are implemented, GTK's list widgets will allow users
62  * to select and unselect items. However, `GtkSelectionModel`s are free to only
63  * implement them partially or not at all. In that case the widgets will not
64  * support the unimplemented operations.
65  * 
66  * When selecting or unselecting is supported by a model, the return values of
67  * the selection functions do *not* indicate if selection or unselection happened.
68  * They are only meant to indicate complete failure, like when this mode of
69  * selecting is not supported by the model.
70  * 
71  * Selections may happen asynchronously, so the only reliable way to find out
72  * when an item was selected is to listen to the signals that indicate selection.
73  */
74 public interface SelectionModelIF{
75 	/** Get the main Gtk struct */
76 	public GtkSelectionModel* getSelectionModelStruct(bool transferOwnership = false);
77 
78 	/** the main Gtk struct as a void* */
79 	protected void* getStruct();
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_selection_model_get_type();
86 	}
87 
88 	/**
89 	 * Gets the set containing all currently selected items in the model.
90 	 *
91 	 * This function may be slow, so if you are only interested in single item,
92 	 * consider using [method@Gtk.SelectionModel.is_selected] or if you are only
93 	 * interested in a few, consider [method@Gtk.SelectionModel.get_selection_in_range].
94 	 *
95 	 * Returns: a `GtkBitset` containing all the values currently
96 	 *     selected in @model. If no items are selected, the bitset is empty.
97 	 *     The bitset must not be modified.
98 	 */
99 	public Bitset getSelection();
100 
101 	/**
102 	 * Gets the set of selected items in a range.
103 	 *
104 	 * This function is an optimization for
105 	 * [method@Gtk.SelectionModel.get_selection] when you are only
106 	 * interested in part of the model's selected state. A common use
107 	 * case is in response to the [signal@Gtk.SelectionModel::selection-changed]
108 	 * signal.
109 	 *
110 	 * Params:
111 	 *     position = start of the queired range
112 	 *     nItems = number of items in the queried range
113 	 *
114 	 * Returns: A `GtkBitset` that matches the selection state
115 	 *     for the given range with all other values being undefined.
116 	 *     The bitset must not be modified.
117 	 */
118 	public Bitset getSelectionInRange(uint position, uint nItems);
119 
120 	/**
121 	 * Checks if the given item is selected.
122 	 *
123 	 * Params:
124 	 *     position = the position of the item to query
125 	 *
126 	 * Returns: %TRUE if the item is selected
127 	 */
128 	public bool isSelected(uint position);
129 
130 	/**
131 	 * Requests to select all items in the model.
132 	 *
133 	 * Returns: %TRUE if this action was supported and no fallback should be
134 	 *     tried. This does not mean that all items are now selected.
135 	 */
136 	public bool selectAll();
137 
138 	/**
139 	 * Requests to select an item in the model.
140 	 *
141 	 * Params:
142 	 *     position = the position of the item to select
143 	 *     unselectRest = whether previously selected items should be unselected
144 	 *
145 	 * Returns: %TRUE if this action was supported and no fallback should be
146 	 *     tried. This does not mean the item was selected.
147 	 */
148 	public bool selectItem(uint position, bool unselectRest);
149 
150 	/**
151 	 * Requests to select a range of items in the model.
152 	 *
153 	 * Params:
154 	 *     position = the first item to select
155 	 *     nItems = the number of items to select
156 	 *     unselectRest = whether previously selected items should be unselected
157 	 *
158 	 * Returns: %TRUE if this action was supported and no fallback should be
159 	 *     tried. This does not mean the range was selected.
160 	 */
161 	public bool selectRange(uint position, uint nItems, bool unselectRest);
162 
163 	/**
164 	 * Helper function for implementations of `GtkSelectionModel`.
165 	 *
166 	 * Call this when a the selection changes to emit the
167 	 * [signal@Gtk.SelectionModel::selection-changed] signal.
168 	 *
169 	 * Params:
170 	 *     position = the first changed item
171 	 *     nItems = the number of changed items
172 	 */
173 	public void selectionChanged(uint position, uint nItems);
174 
175 	/**
176 	 * Make selection changes.
177 	 *
178 	 * This is the most advanced selection updating method that allows
179 	 * the most fine-grained control over selection changes. If you can,
180 	 * you should try the simpler versions, as implementations are more
181 	 * likely to implement support for those.
182 	 *
183 	 * Requests that the selection state of all positions set in @mask
184 	 * be updated to the respective value in the @selected bitmask.
185 	 *
186 	 * In pseudocode, it would look something like this:
187 	 *
188 	 * ```c
189 	 * for (i = 0; i < n_items; i++)
190 	 * {
191 	 * // don't change values not in the mask
192 	 * if (!gtk_bitset_contains (mask, i))
193 	 * continue;
194 	 *
195 	 * if (gtk_bitset_contains (selected, i))
196 	 * select_item (i);
197 	 * else
198 	 * unselect_item (i);
199 	 * }
200 	 *
201 	 * gtk_selection_model_selection_changed (model,
202 	 * first_changed_item,
203 	 * n_changed_items);
204 	 * ```
205 	 *
206 	 * @mask and @selected must not be modified. They may refer to the
207 	 * same bitset, which would mean that every item in the set should
208 	 * be selected.
209 	 *
210 	 * Params:
211 	 *     selected = bitmask specifying if items should be selected or unselected
212 	 *     mask = bitmask specifying which items should be updated
213 	 *
214 	 * Returns: %TRUE if this action was supported and no fallback should be
215 	 *     tried. This does not mean that all items were updated according
216 	 *     to the inputs.
217 	 */
218 	public bool setSelection(Bitset selected, Bitset mask);
219 
220 	/**
221 	 * Requests to unselect all items in the model.
222 	 *
223 	 * Returns: %TRUE if this action was supported and no fallback should be
224 	 *     tried. This does not mean that all items are now unselected.
225 	 */
226 	public bool unselectAll();
227 
228 	/**
229 	 * Requests to unselect an item in the model.
230 	 *
231 	 * Params:
232 	 *     position = the position of the item to unselect
233 	 *
234 	 * Returns: %TRUE if this action was supported and no fallback should be
235 	 *     tried. This does not mean the item was unselected.
236 	 */
237 	public bool unselectItem(uint position);
238 
239 	/**
240 	 * Requests to unselect a range of items in the model.
241 	 *
242 	 * Params:
243 	 *     position = the first item to unselect
244 	 *     nItems = the number of items to unselect
245 	 *
246 	 * Returns: %TRUE if this action was supported and no fallback should be
247 	 *     tried. This does not mean the range was unselected.
248 	 */
249 	public bool unselectRange(uint position, uint nItems);
250 
251 	/**
252 	 * Emitted when the selection state of some of the items in @model changes.
253 	 *
254 	 * Note that this signal does not specify the new selection state of the
255 	 * items, they need to be queried manually. It is also not necessary for
256 	 * a model to change the selection state of any of the items in the selection
257 	 * model, though it would be rather useless to emit such a signal.
258 	 *
259 	 * Params:
260 	 *     position = The first item that may have changed
261 	 *     nItems = number of items with changes
262 	 */
263 	gulong addOnSelectionChanged(void delegate(uint, uint, SelectionModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
264 }